import QtQuick 2.0
import QtQuick.Window 2.0
import BppTable  1.0
import Qt.labs.qmlmodels 1.0
import CustomGeometry 1.0
import QtQuick.Controls 2.12
import "./insp.js" as Inspector
Window {
    visible: true
    width: 640
    height: 480
    id:window1
    title: qsTr("Hello World")

    property var fruitList: [
        {pkid: 1, name: "Apple", cost: 2.45},
        // {pkid: 2, name: "Orange", cost: 3.45},
        // {pkid: 3, name: "Banana", cost: 1.459},
        // {pkid: 4, name: "Strawberry", cost: 1.1467}
      ];
 Column{
    Button{
        height:50
        width:window1.width
        text:"click me"
        onClicked:()=>{
            console.log(bGrid.cellValue(1,1))
            console.log(bGrid.cellValue(0,0))
        }
    }
    CompGrid {
        id: bGrid
        height:window1.height-50
        width:window1.width
        // anchors.fill: parent
        // anchors.margins: 30

        dataHeight: 30
        showOptionsButton: true

        Component {
            id: cellItem

            Rectangle {
                implicitHeight: bGrid.dataHeight
                color: bGrid.getCellBk(row, "highlight")

                CellText {
                    text: bGrid.formatDisplay(display, dataType, 2)
                    horizontalAlignment: bGrid.getAlign(dataType)
                }
                // Button{
                //     height:20
                //     width:50
                //     text:"click me"
                //     onClicked:()=>{
                //         console.log(dataType)
                //         // console.log(bGrid.cellValue(0,0))
                //     }
                // }

                CellClicker {
                    grid: bGrid
                }
            }
        }

        cellDelegate: cellItem

        fromArray: [
            { role: "pkid", title: "ID", dataType: "Int" },
            { role: "name", title: "Name", minWidth: 100 },
            { role: "cost", title: "Cost", dataType: "Dbl" }
         ]
    }
}
    Component.onCompleted: {
        console.log(fruitList)
        bGrid.fillFromJson(fruitList);
    }
}
